package com.eugenema.entity;

/**
 * 实体类：连场
 * @author Eugenema
 * @date 2023-03-01 10:21
 */
public class EvenMatch {
    /** 连场数量 */
    private Integer num;
    /** 连场方向：true 为双，false 为单 */
    private Boolean direction;

    public EvenMatch() {
    }

    public EvenMatch(Integer num, Boolean direction) {
        this.num = num;
        this.direction = direction;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Boolean isDirection() {
        return direction;
    }

    public void setDirection(Boolean direction) {
        this.direction = direction;
    }

    @Override
    public String toString() {
        return num + (String)FutureMatch.directionConverter(direction);
    }

    /**
     * 连场实体类与字符串转换
     * 字符串格式：数字 + 一个汉字（“单”或“双”）
     *
     * @author Eugenema
     * @date 2023/3/5 20:57
     *
     * @param converterStr 要转换的字符串
     *
     * @return 转换后的连场实体类。字符串格式有误或不符合规则，返回 null
     **/
    public static EvenMatch evenMatchConverter(String converterStr) {
        //1、判断字符串格式
        if (!converterStr.matches("^(?!0)\\d+[单|双]$")) {
            return null;
        }
        //2、分割数字和字符串
        String[] split = converterStr.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
        //3、创建连场实体类
        return new EvenMatch(Integer.parseInt(split[0]), (Boolean) FutureMatch.directionConverter(split[1]));
    }
}
